package com.company;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Tools_AdbCommand {
    public static void main(String[] args) {
        Tools_AdbCommand o = new Tools_AdbCommand();
        o.taking_pictures();
    }
    /*
     * 拍照实现方法
     */
    public void taking_pictures() {
        try {
            Process process = Runtime.getRuntime().exec("cmd /c adb devices");
            InputStream fis=process.getInputStream();
            //用一个读输出流类去读
            InputStreamReader isr=new InputStreamReader(fis);
            //用缓冲器读行
            BufferedReader br=new BufferedReader(isr);
            String line=null;
            //直到读完为止
            while((line=br.readLine())!=null)
            {
                System.out.println(line);
            }
            //Process process = Runtime.getRuntime().exec("cmd /c adb shell am start -n com.vinno.healthmonitor/com.vinno.healthmonitor.splashScreen");
            int exitVal = process.waitFor();
            System.out.println("Exited with error code " + exitVal);
            // process.destroy();
            System.out.println("1");
        } catch (IOException | InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    /*
     * 对焦实现方法
     */
    public void focusing() {
        try {
            Process process = Runtime.getRuntime().exec("cmd /c adb shell input keyevent 80");
            Thread.sleep(2000);
            process.destroy();
        }catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
    /*
     * 删除手机照片文件方法
     */
    public void deletecamerafile() {
        try {
            Process process = Runtime.getRuntime().exec("adb shell");
            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
            process.getOutputStream().write("cd /mnt/sdcard/DCIM/\r\n".getBytes());
            process.getOutputStream().write("rm -r Camera/ \r\n".getBytes());
            process.getOutputStream().flush(); //刷新流
            Thread.sleep(2000);
            input.close();
            process.destroy();
            System.out.println("手机中的照片清除完毕...");
        } catch (IOException e) {
            // TODO: handle exception
            e.printStackTrace();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    /*
     * 得到当前测试照片名称的方法
     */
    public void get_photo_name(String Storage_place) {
        try {
            Process process = Runtime.getRuntime().exec("adb shell");
            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
            process.getOutputStream().write("cd /mnt/sdcard/DCIM/Camera/\r\n".getBytes());
            process.getOutputStream().write("ls\r\n".getBytes());
            process.getOutputStream().flush();
            String s = input.readLine();
//            if(Storage_place == "contrast_photo" ) {
//                new Tools_Sql().setcontrast_photo_name(s);
//                System.out.println("照片名称是："+new Tools_Sql().getcontrast_photo_name());
//            }else if (Storage_place == "test_photo") {
//                new Tools_Sql().setTest_photo_name(s);
//                System.out.println("照片名称是："+new Tools_Sql().getTest_photo_name());
//            }else if (Storage_place == "error_photo") {
//                new Tools_Sql().setTest_photo_name(s);
//                System.out.println("照片名称是："+new Tools_Sql().getTest_photo_name());
//
//            }

            input.close();
            process.destroy();


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }
}
